//
//  UserInfoHeader.m
//  CarLifes
//
//  Created by yu on 2017/7/1.
//  Copyright © 2017年 jpas. All rights reserved.
//

#import "UserInfoHeader.h"

@implementation UserInfoHeader

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        if (@available(iOS 13.0, *)) {
            self.backgroundColor = UIColor.secondarySystemGroupedBackgroundColor;
        } else {
            self.backgroundColor = UIColor.whiteColor;
        }
        
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = kBaseColor;
        [self addSubview:_lineView];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"车主信息";
        _titleLabel.font = [UIFont boldSystemFontOfSize:15];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        if (@available(iOS 13.0, *)) {
            UIColor *titleColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                    return kTextLightBlackColor;
                } else {
                    return UIColor.secondaryLabelColor;
                }
            }];
            _titleLabel.textColor = titleColor;
        } else {
            _titleLabel.textColor = kTextLightBlackColor;
        }
        [self addSubview:_titleLabel];
        
        UIView *line = [[UIView alloc] init];
        if (@available(iOS 13.0, *)) {
            UIColor *lineColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                    return kLineGrayColor;
                } else {
                    return UIColor.opaqueSeparatorColor;
                }
            }];
            line.backgroundColor = lineColor;
        } else {
            line.backgroundColor = kLineGrayColor;
        }
        [self addSubview:line];
        
        _lineView.sd_layout
        .leftSpaceToView(self, 8)
        .centerYEqualToView(self)
        .widthIs(2)
        .heightRatioToView(self, 0.5);
        
        _titleLabel.sd_layout
        .leftSpaceToView(_lineView, 5)
        .centerYEqualToView(self)
        .heightRatioToView(self, 1)
        .widthIs(200);
        
        line.sd_layout
        .leftEqualToView(self)
        .rightEqualToView(self)
        .bottomEqualToView(self)
        .heightIs(0.5);
        
    }
    return self;
}

@end
